exports = this
exports.CPANEL.Products = exports.CPANEL.Products || {}

class exports.CPANEL.Products.DataTable
  @init: ->
    $("#products_datatable").DataTable
        pageLength: 25
        bProcessing: true
        bServerSide: true
        stateSave: true
        responsive: true
        sAjaxSource: $("#products_datatable").data('source')
        language: CPANEL.datatableLanguage
        order: [[3, 'desc']]
        columnDefs: [
          { orderable: false, targets: 0 }
          { orderable: false, targets: 4 }
        ]
  @refresh: ->
    $("#products_datatable").DataTable().ajax.reload();

class exports.CPANEL.Products.Qiniu
  @init: ->
    new CPANEL.QiniuUploader
      browse_button: 'product_image',
      FileUploaded_callback: (up, file, info) ->
        # 查看简单反馈
        domain = up.getOption('domain')
        res = JSON.parse(info)
        sourceLink = domain + "/" + res.key
        # console.log("domain:" + domain)
        # console.log("res.key:" + res.key)
        # console.log("sourceLink:" + sourceLink)

        $("#product_avatar_q_key").val(res.key)
        $("#product_avatar_q_bucket").val(res.bucket)
        $("#product_image").attr("src", sourceLink)
